package com.cloudlead.common.lang.security;

import com.cloudlead.common.lang.BaseBean;

import java.util.List;

public class Subject implements BaseBean {

    /**
     *
     */
    private static final long serialVersionUID = 8265364200298983685L;

    protected Principal principal;

    protected LoginSource source;

    protected String currentGroup;

    protected List<String> groups;

    protected List<String> roles;

    protected List<String> privileges;

    public Principal getPrincipal() {
        return principal;
    }

    public void setPrincipal(Principal principal) {
        this.principal = principal;
    }

    public LoginSource getSource() {
        return source;
    }

    public void setSource(LoginSource source) {
        this.source = source;
    }

    public String getCurrentGroup() {
        return currentGroup;
    }

    public void setCurrentGroup(String currentGroup) {
        this.currentGroup = currentGroup;
    }

    public List<String> getGroups() {
        return groups;
    }

    public void setGroups(List<String> groups) {
        this.groups = groups;
    }

    public List<String> getRoles() {
        return roles;
    }

    public void setRoles(List<String> roles) {
        this.roles = roles;
    }

    public boolean hasRole(String role) {
        return roles.contains(role);
    }

    public List<String> getPrivileges() {
        return privileges;
    }

    public void setPrivileges(List<String> privileges) {
        this.privileges = privileges;
    }

    public boolean hasPrivilege(String privilege) {
        return privileges.contains(privilege);
    }

    @Override
    public String toString() {
        return "Subject{" +
                ", principal='" + principal + '\'' +
                ", source=" + source +
                ", groups=" + groups +
                ", roles=" + roles +
                ", privileges=" + privileges +
                '}';
    }
}
